// pages/login/login.js

import Toast from '../../miniprogram_npm/@vant/weapp/toast/toast';


Page({

  /**
   * 页面的初始数据
   */
  data: {
    username: "",
    password: "",

    // 登录的身份
    radio: "",

  },

  username_onChange(event) {
    // console.log(event.detail);
    this.setData({
      username: event.detail
    })
  },

  password_onChange(event) {
    // console.log(event.detail);
    this.setData({
      password: event.detail
    })
  },

  onClickIcon() {
    Toast('忘记密码？请联系管理员 :)');
  },

  radio_onChange(event) {
    this.setData({
      radio: event.detail
    });
   //console.log(event.detail)
  },


  login(res) {
    var radio1;
    radio1 = this.data.radio;
    console.log(this.data.password);
    if(this.data.radio=='report'){
      var that=this;
      wx.request({
      url: 'http://localhost:8088/appClientLogin',
      method:"GET",
      data:{
        CId: this.data.username,
        CPwd: this.data.password,
      },
      success(res){
        var data1 = res.data;
        console.log(data1);
         if("SUCCESS" == data1){
           var url1;
           url1 = `../${radio1}/${radio1}`+"?Id="
           console.log(url1)
           Toast(`${radio1}登陆成功！`);
           wx.navigateTo({
             url: url1+that.data.username,
           });
           
         }
         else Toast(`${radio1}账户或密码错误！`);
       }
    });
    }
    if(this.data.radio=='recive_order'){
      var that=this;
      wx.request({
        url: 'http://localhost:8088/appEmployeeLogin',
        method:"GET",
        data:{
          EId: this.data.username,
          EPwd: this.data.password,
        },
        success(res){
         var data1 = res.data;
         console.log(data1);
          if("SUCCESS" == data1){
            var url1;
            url1 = `../${radio1}/${radio1}`+"?Id="
            console.log(url1)
            Toast(`${radio1}登陆成功！`);
            wx.navigateTo({
              url: url1+that.data.username,
            });
            
          }
          else Toast(`${radio1}账户或密码错误！`);
        }
      });
    }


  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})